home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performScaleConstraint.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  12.4 KB  |  499 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  24 April 1997
  22. //
  23. //  Description:
  24. //        This script provides an option box dialog for the scaleConstraint command.
  25. //
  26. //    Input Arguments:
  27. //        boolean showOptionBox    true - show the option box dialog
  28. //                                false - just execute the command
  29. //
  30.  
  31. //
  32. //  Procedure Name:
  33. //      setOptionVars
  34. //
  35. //  Description:
  36. //        Initialize the option values.
  37. //
  38. //  Input Arguments:
  39. //        Whether to set the options to default values.
  40. //
  41. //  Return Value:
  42. //      None.
  43. //
  44. proc setOptionVars(int $forceFactorySettings)
  45. {
  46.     //    weight
  47.     //
  48.     if ($forceFactorySettings || !`optionVar -exists scaleConstraintWeight`) {
  49.         optionVar -floatValue scaleConstraintWeight 1.0;
  50.     }
  51.  
  52.     // offset values
  53.     //
  54.     if ($forceFactorySettings || 
  55.         !`optionVar -exists scaleConstOffsetX`) {
  56.         optionVar -floatValue scaleConstOffsetX 1.0;
  57.     }
  58.     if ($forceFactorySettings || 
  59.         !`optionVar -exists scaleConstOffsetY`) {
  60.         optionVar -floatValue scaleConstOffsetY 1.0;
  61.     }
  62.     if ($forceFactorySettings || 
  63.         !`optionVar -exists scaleConstOffsetZ`) {
  64.         optionVar -floatValue scaleConstOffsetZ 1.0;
  65.     }
  66.  
  67.     // maintain existing offset
  68.     //
  69.     if ($forceFactorySettings || 
  70.         !`optionVar -exists scaleConstMaintainOffset`) {
  71.         optionVar -intValue scaleConstMaintainOffset 0;
  72.     }
  73.  
  74.     // Constraint axes
  75.     //
  76.     if ($forceFactorySettings ||
  77.         !`optionVar -exists  scaleConstraintAxisX`) {
  78.         optionVar -intValue scaleConstraintAxisX true;
  79.     }
  80.     if ($forceFactorySettings ||
  81.         !`optionVar -exists  scaleConstraintAxisY`) {
  82.         optionVar -intValue scaleConstraintAxisY true;
  83.     }
  84.     if ($forceFactorySettings ||
  85.         !`optionVar -exists  scaleConstraintAxisZ`) {
  86.         optionVar -intValue scaleConstraintAxisZ true;
  87.     }
  88.  
  89. }
  90.  
  91. //
  92. //  Procedure Name:
  93. //      scaleConstraintSetup
  94. //
  95. //  Description:
  96. //        Update the state of the option box UI to reflect the option values.
  97. //
  98. //  Input Arguments:
  99. //      parent               - Top level parent layout of the option box UI.
  100. //                             Required so that UI object names can be 
  101. //                             successfully resolved.
  102. //
  103. //        forceFactorySettings - Whether the option values should be set to
  104. //                             default values.
  105. //
  106. //  Return Value:
  107. //      None.
  108. //
  109. global proc scaleConstraintSetup(string $parent, int $forceFactorySettings)
  110. {
  111.     //    Retrieve the option settings
  112.     //
  113.     setOptionVars($forceFactorySettings);
  114.  
  115.     setParent $parent;
  116.  
  117.     //    Query the optionVar's and set the values into the controls.
  118.  
  119.     //    weight
  120.     //
  121.     floatSliderGrp -edit 
  122.         -value `optionVar -query scaleConstraintWeight`
  123.         scaleConstraintWeight;
  124.  
  125.     float $sx = `optionVar -query scaleConstOffsetX`;
  126.     float $sy = `optionVar -query scaleConstOffsetY`;
  127.     float $sz = `optionVar -query scaleConstOffsetZ`;
  128.     if (`optionVar -query scaleConstMaintainOffset`) {
  129.         checkBoxGrp -edit -value1 1 scaleConstraintMaintainWidget;
  130.         floatFieldGrp -edit -enable 0 offsetField;        
  131.     } else {
  132.         checkBoxGrp -edit -value1 0 scaleConstraintMaintainWidget;
  133.         floatFieldGrp -edit -enable 1 offsetField;
  134.     }
  135.     floatFieldGrp -e -v1 $sx -v2 $sy -v3 $sz offsetField;
  136.  
  137.     //  Axis values
  138.     //
  139.     int $axisX = `optionVar -query scaleConstraintAxisX`;
  140.     int $axisY = `optionVar -query scaleConstraintAxisY`;
  141.     int $axisZ = `optionVar -query scaleConstraintAxisZ`;
  142.     // if all axes are on, select the all box and dim the individual axes
  143.     if ($axisX && $axisY && $axisZ) {
  144.         checkBoxGrp -edit -value1 true axesAll;
  145.         checkBoxGrp -edit -value1 false -value2 false -value3 false axesXYZ;
  146.     }
  147.     // otherwise just select those boxes corresponding to 'on' axes
  148.     else {
  149.         checkBoxGrp -edit -value1 false axesAll;
  150.         checkBoxGrp -edit -value1 $axisX -value2 $axisY -value3 $axisZ axesXYZ; 
  151.     }
  152. }
  153.  
  154. //
  155. //  Procedure Name:
  156. //      scaleConstraintCallback
  157. //
  158. //  Description:
  159. //        Update the option values with the current state of the option box UI.
  160. //
  161. //  Input Arguments:
  162. //      parent - Top level parent layout of the option box UI.  Required so
  163. //               that UI object names can be successfully resolved.
  164. //
  165. //        doIt   - Whether the command should execute.
  166. //
  167. //  Return Value:
  168. //      None.
  169. //
  170. global proc scaleConstraintCallback(string $parent, int $doIt)
  171. {
  172.     setParent $parent;
  173.  
  174.     //    Set the optionVar's from the control values, and then
  175.     //    perform the command.
  176.  
  177.     //    weight
  178.     //
  179.     optionVar -floatValue scaleConstraintWeight
  180.         `floatSliderGrp -query -value scaleConstraintWeight`;
  181.  
  182.     // maintain offset
  183.     //
  184.     optionVar -intValue scaleConstMaintainOffset `checkBoxGrp  -query -value1 scaleConstraintMaintainWidget`;
  185.     
  186.     //    Offset values
  187.     //
  188.     optionVar -floatValue scaleConstOffsetX
  189.         `floatFieldGrp -query -v1 offsetField`;
  190.     optionVar -floatValue scaleConstOffsetY
  191.         `floatFieldGrp -query -v2 offsetField`;
  192.     optionVar -floatValue scaleConstOffsetZ
  193.         `floatFieldGrp -query -v3 offsetField`;
  194.  
  195.     // Axis values
  196.     //
  197.  
  198.     // Either the 'All' box is checked (and so all axes are on) ...
  199.     if ( `checkBoxGrp -query -value1 axesAll` ) {
  200.         optionVar -intValue scaleConstraintAxisX true;
  201.         optionVar -intValue scaleConstraintAxisY true;
  202.         optionVar -intValue scaleConstraintAxisZ true;
  203.     } else {
  204.         // ... Or only those axes specifically selected are on
  205.         optionVar -intValue scaleConstraintAxisX
  206.             `checkBoxGrp -query -value1 axesXYZ`;
  207.         optionVar -intValue scaleConstraintAxisY
  208.             `checkBoxGrp -query -value2 axesXYZ`;
  209.         optionVar -intValue scaleConstraintAxisZ
  210.             `checkBoxGrp -query -value3 axesXYZ`;
  211.     }
  212.  
  213.     if ($doIt) {
  214.         performScaleConstraint 0; 
  215.         addToRecentCommandQueue "performScaleConstraint 0" "ScaleConstraint";
  216.     }
  217. }
  218.  
  219.  
  220. //
  221. //  Procedure Name:
  222. //      scaleConstraintOptions
  223. //
  224. //  Description:
  225. //        Construct the option box UI.  Involves accessing the standard option
  226. //        box and customizing the UI accordingly.
  227. //
  228. //  Input Arguments:
  229. //      None.
  230. //
  231. //  Return Value:
  232. //      None.
  233. //
  234. proc scaleConstraintOptions()
  235. {
  236.     //    Name of the command for this option box.
  237.     //
  238.     string $commandName = "scaleConstraint";
  239.  
  240.     //    Build the option box actions.
  241.     //
  242.     string $callback = ($commandName + "Callback");
  243.     string $setup = ($commandName + "Setup");
  244.  
  245.     //    Get the option box.
  246.     //
  247.     string $layout = getOptionBox();
  248.     setParent $layout;
  249.     
  250.     //    Pass the command name to the option box.
  251.     //
  252.     setOptionBoxCommandName($commandName);
  253.     
  254.     //    Activate the default UI template.
  255.     //
  256.     setUITemplate -pushTemplate DefaultTemplate;
  257.  
  258.     //    Turn on the wait cursor.
  259.     //
  260.     waitCursor -state 1;
  261.  
  262.     tabLayout -scr true -tv false;
  263.     string $parent = `columnLayout -adjustableColumn 1`;
  264.     
  265.     checkBoxGrp
  266.         -label "Maintain Offset"
  267.         -label1 " "
  268.         -annotation "Preserve the initial offset between the object and the target(s)"
  269.         -numberOfCheckBoxes 1
  270.         -cc ("floatFieldGrp -edit -enable (! #1) offsetField;")
  271.         scaleConstraintMaintainWidget;
  272.     
  273.     floatFieldGrp -label "Offset"
  274.         -numberOfFields 3
  275.         offsetField;
  276.  
  277.     separator;
  278.  
  279.     //      Constraint Axes Selection Boxes
  280.     //
  281.  
  282.     // The 'axesAll' checkBoxGrp and the 'axesXYZ' checkBoxGrp are linked
  283.     // such that when 'axesAll' is selected, all the 'axesXYZ' boxes are
  284.     // unselected. And when any 'axesXYZ' box is selected the 'axesAll'
  285.     // box is deselected.
  286.     checkBoxGrp -numberOfCheckBoxes 1 -label "Constraint Axes"
  287.         -label1 "All"
  288.         -onCommand ("checkBoxGrp -edit " +
  289.                     "-value1 false " +
  290.                     "-value2 false " +
  291.                     "-value3 false " +
  292.                     "axesXYZ")
  293.         axesAll;
  294.         
  295.     checkBoxGrp -numberOfCheckBoxes 3
  296.         -label1 "X"
  297.         -label2 "Y"
  298.         -label3 "Z"
  299.         -onCommand ("checkBoxGrp -edit " +
  300.                     "-value1 false " +
  301.                     "axesAll;")
  302.         axesXYZ;
  303.  
  304.     separator;
  305.  
  306.     floatSliderGrp -label "Weight"
  307.         -field true -min 0.0 -max 10.0 
  308.         scaleConstraintWeight;
  309.  
  310.  
  311.     //    Turn off the wait cursor.
  312.     //
  313.     waitCursor -state 0;
  314.     
  315.     //    Deactivate the default UI template.
  316.     //
  317.     setUITemplate -popTemplate;
  318.  
  319.     //    'Apply' button.
  320.     //
  321.     string $applyBtn = getOptionBoxApplyBtn();
  322.     button -edit
  323.         -label "Add"
  324.         -command ($callback + " " + $parent + " " + 1)
  325.         $applyBtn;
  326.  
  327.     //    'Save' button.
  328.     //
  329.     string $saveBtn = getOptionBoxSaveBtn();
  330.     button -edit 
  331.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  332.         $saveBtn;
  333.  
  334.     //    'Reset' button.
  335.     //
  336.     string $resetBtn = getOptionBoxResetBtn();
  337.     button -edit 
  338.         -command ($setup + " " + $parent + " " + 1)
  339.         $resetBtn;
  340.  
  341.     //    Set the option box title.
  342.     //
  343.     setOptionBoxTitle("Scale Constraint Options");
  344.  
  345.     //    Customize the 'Help' menu item text.
  346.     //
  347.     setOptionBoxHelpTag( "Scale" );
  348.  
  349.     //    Set the current values of the option box.
  350.     //
  351.     eval (($setup + " " + $parent + " " + 0));    
  352.     
  353.     //    Show the option box.
  354.     //
  355.     showOptionBox();
  356. }
  357.  
  358. //
  359. //  Procedure Name:
  360. //      scaleConstraintHelp
  361. //
  362. //  Description:
  363. //        Return a short description about this command.
  364. //
  365. //  Input Arguments:
  366. //      None.
  367. //
  368. //  Return Value:
  369. //      string.
  370. //
  371. proc string scaleConstraintHelp()
  372. {
  373.     // ******** Example
  374.     // "  Command: Extrude - create a surface using extrusion.\n" +
  375.     // "Selection: curves and isoparms."
  376.  
  377.     return 
  378.     "  Command: scaleConstraint - constrain the scale to average of the targets\n" +
  379.     "Selection: transforms.";    
  380. }
  381.  
  382. //
  383. //  Procedure Name:
  384. //      assembleCmd
  385. //
  386. //  Description:
  387. //        Construct the command that will apply the option box values.
  388. //
  389. //  Input Arguments:
  390. //      None.
  391. //
  392. //  Return Value:
  393. //      None.
  394. //
  395. proc string assembleCmd()
  396. {
  397.     string $cmd = "scaleConstraint";
  398.  
  399.     setOptionVars(false);
  400.  
  401.     if (`optionVar -query scaleConstMaintainOffset`) {
  402.         $cmd = ($cmd + " -mo");
  403.     } else {
  404.         //    Translate values
  405.         //
  406.         float $tx = `optionVar -query scaleConstOffsetX`;
  407.         float $ty = `optionVar -query scaleConstOffsetY`;
  408.         float $tz = `optionVar -query scaleConstOffsetZ`;
  409.         $cmd = ($cmd + " -offset " + $tx + " " + $ty + " " + $tz );
  410.     }
  411.     
  412.     // Axis values
  413.     //
  414.  
  415.     // The axis values are inverted so that they represent
  416.     // which axes to *skip* as opposed to which axes are on.
  417.     int $axisX = !`optionVar -query scaleConstraintAxisX`;
  418.     int $axisY = !`optionVar -query scaleConstraintAxisY`;
  419.     int $axisZ = !`optionVar -query scaleConstraintAxisZ`;
  420.  
  421.     // If any of these values is true, that means that one
  422.     // or more axes are to be skipped.
  423.     if ($axisX)
  424.         $cmd = ($cmd + " -skip x");
  425.     if ($axisY)
  426.         $cmd = ($cmd + " -skip y");
  427.     if ($axisZ)
  428.         $cmd = ($cmd + " -skip z");
  429.  
  430.     $cmd = ($cmd 
  431.             + " -weight " + `optionVar -query scaleConstraintWeight`);
  432.  
  433.     return $cmd;
  434. }
  435.  
  436. //
  437. //  Procedure Name:
  438. //      performScaleConstraint
  439. //
  440. //  Description:
  441. //        Perform the scaleConstraint command using the corresponding 
  442. //        option values.  This procedure will also show the option box
  443. //        window if necessary as well as construct the command string
  444. //        that will invoke the scaleConstraint command with the current
  445. //        option box values.
  446. //
  447. //  Input Arguments:
  448. //      0 - Execute the command.
  449. //      1 - Show the option box dialog.
  450. //      2 - Return the command.
  451. //
  452. //  Return Value:
  453. //      None.
  454. //
  455. global proc string performScaleConstraint(int $action)
  456. {
  457.     string $cmd = "";
  458.  
  459.     switch ($action) {
  460.  
  461.         //    Execute the command.
  462.         //
  463.         case 0:
  464.             //    Retrieve the option settings
  465.             //
  466.             setOptionVars(false);
  467.  
  468.             //    Get the command.
  469.             //
  470.             $cmd = `assembleCmd`;
  471.  
  472.             //    Execute the command with the option settings.
  473.             //
  474.             evalEcho($cmd);
  475.  
  476.             break;
  477.  
  478.         //    Show the option box.
  479.         //
  480.         case 1:
  481.             scaleConstraintOptions;
  482.             break;
  483.  
  484.         //    Return the command string.
  485.         //
  486.         case 2:
  487.             //    Retrieve the option settings.
  488.             //
  489.             setOptionVars (false);
  490.  
  491.             //    Get the command.
  492.             //
  493.             $cmd = `assembleCmd`;
  494.             break;
  495.     }
  496.     return $cmd;
  497. }
  498.  
  499.